package com.xinghou.platform.file.chain.command.voice;

import java.util.UUID;

import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import com.xinghou.platform.file.model.ResourceContext;
import com.xinghou.platform.util.ConfigUtil;
import com.xinghou.platform.util.FileUtil;

/**
 * 
 * @author wzk
 *
 */
public class InitCommand implements Command{
	private static String url = ConfigUtil.getProperty("save_msgvoice_url");
	@Override
	public boolean execute(Context context) throws Exception {
		@SuppressWarnings("unchecked")
		ResourceContext<byte[], String> resourceContext = (ResourceContext<byte[], String>)context;

		//生成语音路径
		String tmpPath = FileUtil.genPathBydate();
		resourceContext.setRootPath(url, true);
		resourceContext.getSource().setPath("voice/");
		resourceContext.setSubPath(tmpPath, true);
		
		//生成语音ID
		Integer resourceId = 1;
		resourceContext.getRequest().setResourceId(resourceId.toString());
		Integer sourceId = resourceId * 10;
		resourceContext.getSource().setResourceId(sourceId.toString());
		
		//生成语音名称
		String resourceName =  UUID.randomUUID().toString().replace("-", "")  + ".amr";
		resourceContext.setResourceName(resourceName, true);
		
		return false;
	}


}
